import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
public class Course implements Serializable {
    public String a;public String b;public String c;
public Course(String a,String b,String c) {this.a = a;this.b = b;this.c = c;}
    static Scanner sc = new Scanner(System.in);
    public void print() {System.out.println(a);System.out.println(b);System.out.println(c);}
    public static void ENTER() {System.out.println("欢迎");System.out.println("1选课");System.out.println("2查询列表");}
    public static void ENTER2() {System.out.println("1选课");System.out.println("2查询列表");System.out.println("3退课");System.out.println("0退出");}
    public static void enter() {System.out.println("请输入选课的课序号:");}
    public static void enter2() {System.out.println("请输入您想要退课的课序号:(提示:按0退出)");}
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        try{
            int x[] = new int[3];
            Arrays.fill(x,0);
            ObjectOutputStream out  = new ObjectOutputStream(new FileOutputStream("OOO.dat"));
            ObjectInputStream in = new ObjectInputStream(new FileInputStream("OOO.dat"));//序列化
            Course qIn[] = new Course[3];
            String qin[] = new String[3];
            int nn = 0;
            qin[0] = "1数学8:00";
            qin[1] = "2英语9:00";
            qin[2] = "3语文10:00";//课程列表，可手动添加，行首为课序号，对应下面选课的课序号
            ENTER();
            int k = sc.nextInt();
            while(k!=0) {
                switch(k) {
                case 1://输入选课信息
                    System.out.println("想选几门课?");
                    nn = sc.nextInt();
                    if(nn<=0||nn>3) {
                        System.out.println("请输入正确数量!");
                        break;
                    }
                    int kk = 0;
                    for(int i=nn;i>0;i--) {//选课循环，输入课序号就可以选择课程
                        enter();
                        kk = sc.nextInt();
                        switch(kk) {
                        case 1:
                            x[0] = 1;
                            qIn[0] = new Course("1","数学","8:00");
                            break;
                        case 2:
                            x[1] = 1;
                            qIn[1] = new Course("2","英语","9:00");
                            break;
                        case 3:
                            x[2] = 1;
                            qIn[2] = new Course("3","语文","10:00");
                            break;
                            default:System.out.println("请输入正确课序号!");
                            i++;//输入错误的话则重新补一次输入机会
                            break;
                        }
                    }
                    out.writeObject(qIn);//存文件
                    ENTER2();
                    k = sc.nextInt();
                    break;
                case 2://查询课程列表
                    for(int i=0;i<3;i++) {
                        System.out.println(qin[i]);
                    }
                    ENTER2();
                    k = sc.nextInt();
                    break;
                case 3://退课
                    int mm = 1;
                    while(mm!=0) {
                        enter2();
                        mm = sc.nextInt();
                        switch(mm) {
                        case 1:
                            x[0] = 0;
                            qIn[0] = null;
                            break;
                        case 2:
                            x[1] = 0;
                            qIn[1] = null;
                            break;
                        case 3:
                            x[2] = 0;
                            qIn[2] = null;
                            break;
                        case 0:
                            break;
                            default:System.out.println("请输入正确课序号!");
                            break;
                        }
                    }
                    out.writeObject(qIn);//写入文件
                    ENTER2();
                    k = sc.nextInt();
                    break;
                    default:System.out.println("请输入正确数字!");
                    ENTER2();
                    k = sc.nextInt();
                    break;
                }
            }
            out.close();
            in.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}